package com.googlecode.wannabet.service;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class ServiceHandlerServlet extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String uri = request.getRequestURI();
		
		IWannabetService wannabetService = null;
		
		if("/service/tournaments".equals(uri)) {
			wannabetService = new TournamentsService();
		} else if("/service/tourDetails".equals(uri)) {
			wannabetService = new TournamentDetailsService();
		} else if("/service/userDetails".equals(uri)) {
			wannabetService = new UserDetailsService();
		}
		
		if(wannabetService != null) {
			String xmlResponse = wannabetService.processRequest(request, response);
			if(xmlResponse != null) {
				response.setStatus(HttpServletResponse.SC_OK);
				response.setContentType("text/xml");
				response.getWriter().println(xmlResponse);
			}
		} else {
			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
		}
	}

}
